#include "myeventlooper.h"


MyEventLooper::MyEventLooper()
{
    QObject::connect(this, &MyEventLooper::loopSig, this, &MyEventLooper::rcvLoopSig);
}

void MyEventLooper::moveToThread(QThread *thread)
{
    QObject::moveToThread(thread);
    emit loopSig();
}

void MyEventLooper::startReadFile(QString filename)
{
    qDebug() << "startReadFile" ;
    file.setFileName(filename);
    file.open(QFile::ReadOnly);
    readFlag=true;
}

void MyEventLooper::rcvLoopSig()
{
    while(1){
        QThread::msleep(1000);
        if(readFlag == false)
            continue;
        //1k1k的读取文件，为了看进度条的效果
        char data[1024];
        qint64 cnt=file.read(data, 1024);
        cntRead += cnt;
        unsigned int size=file.size();
        //
        if(cntRead >= size){
            file.close();
            readFlag=false;
        }
        emit processGoSig(cntRead*100/size);
    }
}
